package com.bos.service.imp;

import com.bos.dao.IRoleDao;
import com.bos.domain.Function;
import com.bos.domain.Role;
import com.bos.service.IRoleService;
import com.bos.utils.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Set;

/**
 * @author Administrator
 */
@Service
@Transactional
public class IRoleServiceImp implements IRoleService {

    @Autowired
    private IRoleDao roleDao;

    @Override
    public void save(Role role, String functionIds) {
        String[] funcIds = functionIds.split(",");
        Set functions = role.getFunctions();
        //这里指定了由角色维护多对多关系
        for (String funcID : funcIds) {
            Function func = new Function(funcID);
            functions.add(func);
        }
        roleDao.save(role);
    }

    @Override
    public void pageQuery(PageBean pageBean) {
        roleDao.pageQuery(pageBean);
    }

    @Override
    public List<Role> findAll() {
        return roleDao.findAll();
    }
}
